package com.da.javatest.test.basic;

import org.junit.Test;

/**
 * @author JokerDa.
 * @date 2025/3/20 15:57
 * Description:
 */
public class JavaTest3 {
    @Test
    public void test1() {
        Thread t1 = new Thread(() -> {

        });
        System.out.println(t1.getState());
    }

    @Test
    public void test2() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while (true) {

            }
        });
        t1.start();
        Thread.sleep(500);
        System.out.println(t1.getState());
    }

    @Test
    public void test3() throws InterruptedException {
        Object obj = new Object();
        Thread t1 = new Thread(() -> {
            // t1线程拿不到锁资源，导致变为BLOCKED状态
            synchronized (obj) {

            }
        });
        // main线程拿到obj的锁资源
        synchronized (obj) {
            t1.start();
            Thread.sleep(500);
            System.out.println(t1.getState());
        }
    }

    @Test
    public void test4() throws InterruptedException {
        Object obj = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (obj) {
                try {
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        Thread.sleep(500);
        System.out.println(t1.getState());
    }

    @Test
    public void test5() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t1.start();
        Thread.sleep(500);
        System.out.println(t1.getState());
    }

    @Test
    public void test6() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t1.start();
        Thread.sleep(1000);
        System.out.println(t1.getState());
    }

    @Test
    public void test7() {
        System.out.println(Integer.toBinaryString(10));
    }
}
